# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gtkmm3
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.24.3
pkgrel=3
pkgdesc="C++ bindings for gtk3 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.gtkmm.org/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-atkmm"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-pangomm"
         "${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-libxslt"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('strip' '!debug' 'staticlibs')
source=("https://download.gnome.org/sources/gtkmm/${pkgver%.*}/gtkmm-${pkgver}.tar.xz"
        "0001-fix-export.patch"
        "0002-fix-untracked.patch")
sha256sums=('60497c4f7f354c3bd2557485f0254f8b7b4cf4bebc9fee0be26a77744eacd435'
            'a21baa04d6d887f1bf9fd012d0130c8b282aa4d7b002504e3bfce18894c173ea'
            '047b7f643c21671ec28328cd3e6b9db5fb78426129597ea8b124a0c38f4db096')

prepare() {
  cd "${srcdir}/gtkmm-${pkgver}"

  # https://gitlab.gnome.org/GNOME/gtkmm/-/issues/88
  patch -Np1 -i "${srcdir}/0001-fix-export.patch"
  patch -Np1 -i "${srcdir}/0002-fix-untracked.patch"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("--buildtype=release")
  else
    extra_config+=("--buildtype=debug")
  fi

  CFLAGS+=" -Wno-attributes" \
  CXXFLAGS+=" -Wno-attributes" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    "${extra_config[@]}" \
    --wrap-mode=nodownload \
    --default-library=both \
    --auto-features=enabled \
    -Dmaintainer-mode=false \
    -Dbuild-documentation=false \
    -Dbuild-demos=false \
    -Dbuild-tests=true \
    "../gtkmm-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  ${MINGW_PREFIX}/bin/meson.exe test || true
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install

  install -Dm644 "${srcdir}/gtkmm-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/gtkmm-${pkgver}/COPYING.tools" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.tools"
}
